package deep7jvmdvm;

import utils.PrintlnUtils;

/*
Java 内存模型与线程
https://blog.csdn.net/ChinaDragon10/article/details/125884509?csdn_share_tail=%7B%22type%22%3A%22blog%22%2C%22rType%22%3A%22article%22%2C%22rId%22%3A%22125884509%22%2C%22source%22%3A%22ChinaDragon10%22%7D&ctrtid=fgK2e

缓存一致性问题
 */
public class TestJMM1 {
    public static int x = 0;
    public static int y = 0;

    public static void main(String[] args) {
        Thread p1 = new Thread() {
            @Override
            public void run() {
                int r1 = x;
                y = 1;
                PrintlnUtils.println("r1 = " + r1 + " , x = " + x + " , y = " + y);

            }
        };


        Thread p2 = new Thread() {
            @Override
            public void run() {
                int r2 = y;
                x = 2;

                PrintlnUtils.println("r2 = " + r2 + " , x = " + x+ " , y = " + y);

            }
        };

        p1.start();
        p2.start();

        //  r1 = 0 , x = 0 , y = 1
        //
        //    r2 = 1 , x = 2 , y = 1

    }
}
